#ifndef _MYHEAP_H_
#define _MYHEAP_H_

#include "Type.h"
#include <string>

class CMyHeap
{
public:
	CMyHeap(LPCTSTR pszClassName = NULL);
	~CMyHeap();

public:
	void*	Alloc(size_t size);
	void	Free(void* ptr);
	BOOL	IsValidPt(void* p);
protected:
	HANDLE			m_hHeap;
	LONG			m_uNumAllocsInHeap;
	LONG			m_lMaxAllocsInHeap;
	std::string		m_strName;
};

#define	MYHEAP_DECLARATION(VAR)										\
	void   operator delete	(void* p)	{ VAR.Free(p); }			\
	void*  operator new	(size_t size)	{ return VAR.Alloc(size); }	\
	void   operator delete[] (void* p)	{ VAR.Free(p); }			\
	void*  operator new[] (size_t size)	{ return VAR.Alloc(size); }	\
public:																\
	static BOOL		IsValidPt(void* p)	{ return VAR.IsValidPt(p); }\
protected:															\
	static CMyHeap	VAR;


#define	MYHEAP_IMPLEMENTATION(T,VAR)			\
CMyHeap	T::VAR(#T);								

#endif // define _MYHEAP_H_
